package cn.bd13.login.controller;

import cn.bd13.login.entity.LoginForm;
import cn.bd13.login.entity.ReturnResult;
import cn.bd13.login.entity.User;
import cn.bd13.login.service.Service;
import cn.bd13.login.utils.ReturnUtils;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * ClassName：Controller
 * Package:cn.kgc.bd13.bootlogin.controller
 * Description:
 *
 * @Date:2020/4/29 15:07
 * @Author:zhangqiang@kgc.cn
 */
@RestController
@RequestMapping("/user")
public class Controller {
    @Resource
    private Service service;

    @RequestMapping("/testCon")
    public String testCon(){
        System.out.println("enter");
        return "hello mmp!";
    }

   @RequestMapping(value = "/login",method = RequestMethod.POST)
    public ReturnResult login(@RequestBody LoginForm loginForm){
       System.out.println("收到了"+loginForm);
       User user=service.login(loginForm.getName());
       if (user!=null){
           if (user.getPassword().equals(loginForm.getPassword())){
               //成功
               return ReturnUtils.returnSuccess();
           }else {
               //密码错误
               return ReturnUtils.returnFailed(400,"wrong password");
           }
       }else {
           //失败
           return ReturnUtils.returnFailed(400,"wrong name");
       }
    }
}
